package sharing

import admin.User
import grails.converters.JSON

class UserController {

 def  userService
    /**
     * 分页组合查询
     * @return
     */
    def userInfo(){
        def result=userService.userInfo(params)
        render result as JSON
    }

    /**
     * 删除用户
     * @return
     */
    def delUser(){
        def result=["code":0,"msg":""]
        log.debug(params)
        def  count=userService.delUser(params)
        if(count.sucess==true){
            result.msg=1
        }else {
            result.msg=0
        }
        render result as JSON
    }
    /**
     * 修改回显数据
     */
    def editById(){
        log.debug(params)
        def  user=User.findByUserId(params.userId)
//        def user=loginService.editById(params)
        render(view: "/admin/edit",model: [user:user])
    }
    /**
     * 修改数据
     */
    def updateUser(){
        def result=["code":0,"msg":""]
        println(params)
        int count= userService.updateUser(params)
        if(count>0){
            result.msg=1
        }else {
            result.msg=0
        }
        render result as JSON
    }
    /**
     * 新增用户
     */
    def saveUser(){
        def result=["code":0,"msg":""]
        log.debug(params)
        int count=userService.saveUser(params)
        if(count>0){
            result.msg=1
        }else {
            result.msg=0
        }
        render result as JSON
    }
    /**
     * 用户退出
     */
    def logout(){
        render(view: "/admin/login")
    }
}
